<template>
  <div>
    <van-nav-bar title="搜索结果" left-arrow @click-left="$router.go(-1)" />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        :to="`/details/?article_id=${item.art_id}`"
        v-for="(item, index) in list"
        :key="index"
        :value="item.title"
      />
    </van-list>
  </div>
</template>

<script>
import { searchApi } from '@/Api'

export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1
    }
  },

  methods: {
    //   进到页面发送请求获取数据
    async onLoad () {
      let res = await searchApi({
        q: this.$route.query.ser,
        page: this.page
      })
      this.list.push(...res.data.data.results)

      this.page++

      this.loading = false
      if (this.list.length >= res.data.data.total_count) {
        this.finished = true
      }
      console.log(res)
    }
  }
}
</script>

<style></style>
